import {defineStore} from 'pinia'
import {ref} from 'vue'

const useUserInfoStore = defineStore('userInfo', () => {
    //定义状态相关的内容
    const ACCESS_TOKEN = ref(null)
    const REFRESH_TOKEN = ref(null)
    const user = ref(null)
    const tenantId = ref(1)

    const setAccessToken = (data) => {
        ACCESS_TOKEN.value = data
    }
    const setRefreshToken = (data) => {
        REFRESH_TOKEN.value = data
    }

    const setUser = (data) => {
        user.value = data
    }

    const setTenantId = (data) => {
        tenantId.value = data
    }

    // 删除用户缓存
    const deleteUserCache = () => {
        user.value = null
    }

    // 删除token
    const removeToken = () => {
        ACCESS_TOKEN.value = null
        REFRESH_TOKEN.value = null
    }

    return {
        ACCESS_TOKEN,
        REFRESH_TOKEN,
        user,
        tenantId,
        setAccessToken,
        setRefreshToken,
        setUser,
        setTenantId,
        deleteUserCache,
        removeToken
    }

}, {persist: true})

export default useUserInfoStore;